package com.tengfei.blogsystem.controller.admin;

/**
 * @version v1.0
 * @author} feige
 * @date 2021-10-15-16:22
 * @description
 */

import com.tengfei.blogsystem.pojo.FriendsLink;
import com.tengfei.blogsystem.response.ResponseResult;
import com.tengfei.blogsystem.service.ILinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 友链api
 */
@PreAuthorize("@permission.admin()")    //需要管理员权限
@RestController
@RequestMapping("/admin/link")
public class LinkAdminApi {

    @Autowired
    ILinkService linkService;

    /**
     * 获取友链列表
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list/{page}/{size}")
    public ResponseResult listLink(@PathVariable("page") int page, @PathVariable("size") int size) {
        return linkService.listLink(page, size);
    }

    /**
     * 添加友链
     *
     * @param link
     * @return
     */
    @PostMapping
    public ResponseResult uploadLink(@RequestBody FriendsLink link) {
        return linkService.uploadLink(link);
    }

    /**
     * 删除友链
     *
     * @param linkId
     * @return
     */
    @DeleteMapping("/{linkId}")
    public ResponseResult deleteLink(@PathVariable("linkId") String linkId) {
        return linkService.deleteLinkByUpdateState(linkId);
    }

    /**
     * 修改友链
     *
     * @param linkId
     * @param link
     * @return
     */
    @PutMapping("/{linkId}")
    public ResponseResult updateLink(@PathVariable("linkId") String linkId, @RequestBody FriendsLink link) {
        return linkService.updateLink(linkId,link);
    }

    /**
     * 查找友链
     *
     * @param linkId
     * @return
     */
    @GetMapping("/{linkId}")
    public ResponseResult getLink(@PathVariable("linkId") String linkId) {
        return linkService.getLink(linkId);
    }
}
